home *** CD-ROM | disk | FTP | other *** search
- Path: pop.gnn.com!HoangTQ
- From: Tuyen Hoang <HoangTQ@gnn.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Need Help With CSC Homework
- Date: Sat, 16 Mar 1996 17:26:03
- Organization: GNN
- Message-ID: <4iff2c$p2i@news-e2b.gnn.com>
- References: <4g0qq4$o0@news.nevada.edu>
- NNTP-Posting-Host: www-41-87.gnn.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset="us-ascii"
- X-GNN-NewsServer-Posting-Date: 16 Mar 1996 22:24:12 GMT
- X-Mailer: GNNmessenger 1.2
-
- Dear Troy
-
- I found some serious error in your code, and you might want to look at my
- comment in the pfun.c file
-
- There are serious problems in your algorithm, too. You use an char array[21]
- for store the Roman number, so the greatest number is 20,000(20 letters M).
- How about the next one? 19,999? No, it's 19,500(19 letters M and 1 for D)
- those numbers from 19,501 to 19,999 are *out* of your hand. There are more,
- 19,100(19 letters M and 1 for C) is ok, but those numbers from 19,101 to
- 19,499 are all gone. I don't have the patient to count all of them, but at
- least, I do know the problem begins at 9,888(MMM MMM MMM DCCC LXXX VIII : 21
- letters). Do I surprise you?
-
- The second problem is that there are NO Roman number IIII or VIIII as you try
- to implement, as I know number four is IV and number 9 is IX, ect.
- Suppose that your implement is acceptable, so you jump in to trouble at 6,999
- (MMM MMM DCCCC LXXXX VIIII : 21 letter) much earlier than the ancient Romans
- did.
-
- Increase the value of MAXLENGTH won't solve this problem, the correct
- solution is using dynamic allocation: allocate the char* after calculate it
- length.
-
- If you want a hasty solution, I have it handy: the value range for type
- unsigned int is from 0 to 65,xxx(for Turbo C), therefore for your Roman
- number's safety, you should set MAXLENGTH to 65+15+1 = 81. If you want to use
- long instead, you should increase MAXLENGTH accordingly.
- If I were you, I would rewiew the algorithm and rewrite the whole thing
- again. I don't know if you have time to do it again. So good luck.
-
- Tuyen Hoang.
-
-